package com.lizx.framework.web.smart.framework.core.utils;

import org.apache.log4j.Logger;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @Author: 李宁 William-Li
 * @Description:
 * @Date: Create in 2019/1/18 4:51 PM
 */
public class StreamUtil {
    private static final Logger LOGGER = Logger.getLogger(StreamUtil.class);

    /**
     * 从输入中获取字符串
     * @param is
     * @return
     */
    public static String getString(InputStream is){
        StringBuilder sb = new StringBuilder();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is));
            String line = null;
            while ((line = reader.readLine()) != null){
                sb.append(line);
            }
        }catch (Exception e){
            LOGGER.error("输入流读取失败"+e);
            throw new RuntimeException(e);
        }
        return sb.toString();
    }
}
